home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************/
- /* ReadIntoTE */
- /* */
- /* Reads open file into existing TextEdit record */
- /************************************************************************************/
-
- #include "MyHeaders.h"
-
- long ReadIntoTE(short pathRefNum, TEHandle hTE)
- {
- long byteCount = 256; /* bytes requested / returned */
- OSErr readErr; /* return from I/O routines */
- long bytesRead = 0; /* total of bytes returned */
- Ptr beginP; /* ptr to begin of temp I/O area */
- Ptr nextP; /* ptr to next avail pos in I/O ara */
-
- CursorSelect (NIL, NIL, watchCursor); /* set watch cursor */
-
- readErr = SetFPos (pathRefNum, fsFromStart, 0); /* position file ptr to begin */
-
- beginP = NewPtr(32767); /* get a temporary I/O area */
- nextP = beginP; /* next avail pos is at top */
-
- readErr = noErr; /* initialize before read loop */
- while (readErr == noErr) /* read till error or EOF */
- {
- readErr = FSRead (pathRefNum, &byteCount, nextP); /* read a block */
- bytesRead += byteCount; /* add bytes to total */
- nextP += byteCount; /* reset nxt avail pos */
- }
-
- TESetText (beginP, bytesRead, hTE); /* copy into TE record */
- TESetSelect (0, 0, hTE); /* set selection at top */
-
- DisposPtr (beginP); /* release temporary I/O area */
-
- return bytesRead; /* return total no of bytes */
- }